﻿Imports System.Windows.Forms

Public Class FrmOptions

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        If TbCovoitureur(1) <> TxtCovoiturreur1.Text Then
            SaveSetting("Covoiturage", "Parametres", "Covoitureur1", TxtCovoiturreur1.Text)
            TbCovoitureur(1) = TxtCovoiturreur1.Text
        End If

        If TbCovoitureur(2) <> TxtCovoiturreur2.Text Then
            SaveSetting("Covoiturage", "Parametres", "Covoitureur2", TxtCovoiturreur2.Text)
            TbCovoitureur(2) = TxtCovoiturreur2.Text
        End If

        If TbCovoitureur(3) <> TxtCovoiturreur3.Text Then
            SaveSetting("Covoiturage", "Parametres", "Covoitureur3", TxtCovoiturreur3.Text)
            TbCovoitureur(3) = TxtCovoiturreur3.Text
        End If

        If TbCovoitureur(4) <> TxtCovoiturreur4.Text Then
            SaveSetting("Covoiturage", "Parametres", "Covoitureur4", TxtCovoiturreur4.Text)
            TbCovoitureur(4) = TxtCovoiturreur4.Text
        End If

        If MskDistanceTrajet.Text <> DistanceTrajet Then
            DistanceTrajet = MskDistanceTrajet.Text
            SaveSetting("Covoiturage", "Parametres", "DistanceTrajet", DistanceTrajet)
        End If

        If MskPrixCarburant.Text <> PrixCarburant Then
            PrixCarburant = MskPrixCarburant.Text
            SaveSetting("Covoiturage", "Parametres", "PrixCarburant", PrixCarburant)
        End If

        If MskConsoVoiture.Text <> ConsoVoiture Then
            ConsoVoiture = MskConsoVoiture.Text
            SaveSetting("Covoiturage", "Parametres", "ConsoVoiture", ConsoVoiture)
        End If

        If TxtCoutTrajet.Text <> CoutTrajet Then
            CoutTrajet = TxtCoutTrajet.Text
            SaveSetting("Covoiturage", "Parametres", "CoutTrajet", CoutTrajet)
        End If

        If TxtCoKm.Text <> CoKm Then
            SaveSetting("Covoiturage", "Parametres", "CoKm", TxtCoKm.Text)
            CoKm = TxtCoKm.Text
        End If
        If TxtCoParcour.Text <> CoKm Then
            SaveSetting("Covoiturage", "Parametres", "CoParcour", TxtCoParcour.Text)
            CoParcour = TxtCoParcour.Text
        End If

        If LblCouleur1.BackColor <> TbCouleur(1) Then
            TbCouleur(1) = LblCouleur1.BackColor
            SaveSetting("Covoiturage", "Parametres", "Couleur1", TbCouleur(1).ToArgb.ToString)
        End If

        If LblCouleur2.BackColor <> TbCouleur(2) Then
            TbCouleur(2) = LblCouleur2.BackColor
            SaveSetting("Covoiturage", "Parametres", "Couleur2", TbCouleur(2).ToArgb.ToString)
        End If

        If LblCouleur3.BackColor <> TbCouleur(3) Then
            TbCouleur(3) = LblCouleur3.BackColor
            SaveSetting("Covoiturage", "Parametres", "Couleur3", TbCouleur(3).ToArgb.ToString)
        End If

        If LblCouleur4.BackColor <> TbCouleur(4) Then
            TbCouleur(4) = LblCouleur4.BackColor
            SaveSetting("Covoiturage", "Parametres", "Couleur4", TbCouleur(4).ToArgb.ToString)
        End If

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()

    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub FrmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For i = 1 To 4
            If TbCovoitureur.Count > i Then
                GroupBox1.Controls("TxtCovoiturreur" & i).Text = TbCovoitureur(i)
                GroupBox1.Controls("LblCouleur" & i).BackColor = TbCouleur(i)
            Else
                GroupBox1.Controls("TxtCovoiturreur" & i).Text = ""
                GroupBox1.Controls("LblCouleur" & i).BackColor = TbCouleur(i)
            End If
        Next

        MskDistanceTrajet.Text = DistanceTrajet
        MskPrixCarburant.Text = PrixCarburant
        MskConsoVoiture.Text = ConsoVoiture
        TxtCoKm.Text = CoKm
        TxtCoParcour.Text = CoParcour

        If Val(MskPrixCarburant.Text) > 0 Then
            TxtSousTotal.Text = ((Val(MskDistanceTrajet.Text) * CSng(MskConsoVoiture.Text)) / 100) * MskPrixCarburant.Text
            TxtCoutTrajet.Text = TxtSousTotal.Text + Val(MskDistanceTrajet.Text) * CSng(TxtUsure.Text)
        Else
            TxtSousTotal.Text = 0
            TxtCoutTrajet.Text = 0
        End If


    End Sub

    Private Sub MskDistanceTrajet_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MskDistanceTrajet.KeyUp

        If Val(MskPrixCarburant.Text) > 0 And Val(MskDistanceTrajet.Text) > 0 Then
            TxtSousTotal.Text = ((Val(MskDistanceTrajet.Text) * CSng(MskConsoVoiture.Text)) / 100) * MskPrixCarburant.Text
            TxtCoutTrajet.Text = TxtSousTotal.Text + MskDistanceTrajet.Text * TxtUsure.Text
            TxtCoParcour.Text = (Val(TxtCoKm.Text) * MskDistanceTrajet.Text) / 1000
        Else
            TxtSousTotal.Text = 0
            TxtCoutTrajet.Text = 0
            TxtCoParcour.Text = 0
        End If

    End Sub

    Private Sub MskConsoVoiture_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)

        If Val(MskPrixCarburant.Text) > 0 Then
            If MskConsoVoiture.Text <> " ," Then
                TxtSousTotal.Text = ((Val(MskDistanceTrajet.Text) * CSng(MskConsoVoiture.Text)) / 100) * MskPrixCarburant.Text
                TxtCoutTrajet.Text = TxtSousTotal.Text + MskDistanceTrajet.Text * TxtUsure.Text
            Else
                TxtSousTotal.Text = ((Val(MskDistanceTrajet.Text) * (0)) / 100) * MskPrixCarburant.Text
                TxtCoutTrajet.Text = TxtSousTotal.Text + MskDistanceTrajet.Text * TxtUsure.Text
            End If
        Else
            TxtSousTotal.Text = 0
            TxtCoutTrajet.Text = 0
        End If

    End Sub

    Private Sub MskPrixCarburant_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If Val(MskPrixCarburant.Text) > 0 Then
            TxtSousTotal.Text = ((Val(MskDistanceTrajet.Text) * CSng(MskConsoVoiture.Text)) / 100) * MskPrixCarburant.Text
            TxtCoutTrajet.Text = TxtSousTotal.Text + MskDistanceTrajet.Text * TxtUsure.Text
        Else
            TxtSousTotal.Text = 0
            TxtCoutTrajet.Text = 0
        End If

    End Sub

    Private Sub MskDistanceTrajet_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles MskDistanceTrajet.MaskInputRejected

    End Sub

    Private Sub TxtCoKm_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        If Val(TxtCoKm.Text) > 0 Then
            TxtCoParcour.Text = (Val(TxtCoKm.Text) * MskDistanceTrajet.Text) / 1000
        Else
            TxtCoParcour.Text = 0
        End If

    End Sub

    Private Sub LblCouleur1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblCouleur1.Click

        ColorDialog1.CustomColors = New Integer() {ColorTranslator.ToWin32(Color.LightPink), ColorTranslator.ToWin32(Color.LightBlue), ColorTranslator.ToWin32(Color.LightCoral), ColorTranslator.ToWin32(Color.LightGreen)}
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            LblCouleur1.BackColor = ColorDialog1.Color
        End If

    End Sub

    Private Sub LblCouleur2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblCouleur2.Click

        ColorDialog1.CustomColors = New Integer() {ColorTranslator.ToWin32(Color.LightPink), ColorTranslator.ToWin32(Color.LightBlue), ColorTranslator.ToWin32(Color.LightCoral), ColorTranslator.ToWin32(Color.LightGreen)}
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            LblCouleur2.BackColor = ColorDialog1.Color
        End If

    End Sub

    Private Sub LblCouleur3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblCouleur3.Click

        ColorDialog1.CustomColors = New Integer() {ColorTranslator.ToWin32(Color.LightPink), ColorTranslator.ToWin32(Color.LightBlue), ColorTranslator.ToWin32(Color.LightCoral), ColorTranslator.ToWin32(Color.LightGreen)}
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            LblCouleur3.BackColor = ColorDialog1.Color
        End If

    End Sub

    Private Sub LblCouleur4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblCouleur4.Click

        ColorDialog1.CustomColors = New Integer() {ColorTranslator.ToWin32(Color.LightPink), ColorTranslator.ToWin32(Color.LightBlue), ColorTranslator.ToWin32(Color.LightCoral), ColorTranslator.ToWin32(Color.LightGreen)}
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            LblCouleur4.BackColor = ColorDialog1.Color
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        LblCouleur1.BackColor = Color.LightPink
        LblCouleur2.BackColor = Color.LightBlue
        LblCouleur3.BackColor = Color.LightCoral
        LblCouleur4.BackColor = Color.LightGreen

    End Sub
End Class
